package logic

import (
	"context"
	"user-regist/userrpc/userrpc"

	"user-regist/api/internal/svc"
	"user-regist/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserLoginLogic) UserLogin(req *types.UserLoginRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	login, err := l.svcCtx.UserRpc.UserLogin(l.ctx, &userrpc.UserLoginRequest{
		Account:  req.Account,
		Password: req.Password,
		Image:    req.Image,
		SendSms:  req.SendSms,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "登陆成功",
		Code:    200,
		Data:    login,
	}, nil
}
